package com.example.hospital.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.hospital.pojo.*;
import com.example.hospital.service.IRbService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.time.LocalDateTime;

@Api(tags = "RbController")
@RestController
@RequestMapping("/Rb")
public class RbController {
    @Autowired
    private IRbService iRbService;
    @ApiOperation(value = "为病人添加基本信息标签")
    @PostMapping("/")
    public RespBean addBasic(@RequestBody Rb rb){
        LocalDate endDate = rb.getEndDate();
        rb.setEndDate(endDate);
        rb.setCreateDate(LocalDate.now());
        if(iRbService.save(rb)){
            return RespBean.success("添加成功");
        }
        return RespBean.error("添加失败");
    }

    @ApiOperation(value = "删除病人基本信息标签")
    @DeleteMapping("/{id}")
    public RespBean deleteByid(@PathVariable Integer id){
        if(iRbService.removeById(id)){
            return RespBean.success("删除成功");
        }
        return RespBean.error("删除失败");
    }
    @ApiOperation(value = "删除病人基本信息标签")
    @DeleteMapping("/delete")
    public RespBean deleteByid(@RequestBody RbVO rbVO){
        int id = rbVO.getId();
        int bid = rbVO.getBid();
        LambdaQueryWrapper<Rb> lam = new LambdaQueryWrapper<>();
        lam.eq(Rb::getPid,id).eq(Rb::getBid,bid);
        if(iRbService.remove(lam)){
            return RespBean.success("删除成功");
        }
        return RespBean.error("删除失败");
    }
}
